#include <bits/stdc++.h>
using namespace std;

class Solution {
public:
    bool isPerfectSquare(int num) {
        int left = 0; int right = num;
        int ans = -1;
        while(left <= right){
            int mid = (left + right)>>1;
            if((long long)mid*mid <= num){
                ans = mid;
                left = mid + 1;
            }
            else right = mid - 1;
        }
        return ans*ans == num;
    }
};